package com.drg.center.controller;

import com.drg.center.entity.param.SysLoginDTO;
import com.drg.center.entity.param.SysPwdEditDTO;
import com.drg.center.entity.param.SysUsernameEditDTO;
import com.drg.center.entity.result.SysLoginVO;
import com.drg.center.entity.result.SysSubResVO;
import com.drg.center.entity.result.SysSubVO;
import com.drg.center.entity.result.SysVerifyCodeVO;
import com.guaike.core.entity.result.Result;
import com.drg.center.service.SysLoginService;
import com.drg.center.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author: zhangxilin
 * @Date: 2023/10/30
 */

@RestController
@RequestMapping("/sys")
@Api(tags = "系统-系统接口组")
public class SysLoginController {

    @Autowired
    private SysLoginService sysLoginService;
    @Autowired
    private SysUserService sysUserService;

    @PostMapping("/login")
    @ApiOperation(value = "登录")
    public Result<SysLoginVO> login(@Valid @RequestBody SysLoginDTO param){
        return sysLoginService.login(param);
    }

    @PostMapping("/logout")
    @ApiOperation(value = "登出")
    public Result<Boolean> logout(){
        return sysLoginService.logout();
    }

    @GetMapping("/getImageVerifyCode")
    @ApiOperation(value = "获取图形验证码")
    public Result<SysVerifyCodeVO> getImageVerify(){
        return sysLoginService.getImageVerify();
    }

    @PostMapping("/pwd/edit")
    @ApiOperation(value = "修改密码")
    public Result<Boolean> updatePwd(@Valid @RequestBody SysPwdEditDTO param){
        return sysUserService.updatePwd(param);
    }

    @PostMapping("/username/edit")
    @ApiOperation(value = "修改账号手机号")
    public Result<Boolean> updateUsername(@Valid @RequestBody SysUsernameEditDTO param){
        return sysUserService.updateUsername(param);
    }

    @GetMapping("/sub/list")
    @ApiOperation(value = "子系统列表")
    public Result<List<SysSubVO>> findSysList(){
       return sysLoginService.findSysList();
    }

    @GetMapping("/sub/menu")
    @ApiOperation(value = "子系统菜单")
    public Result<SysSubResVO> findMenu(@ApiParam("子系统编号") @RequestParam("sysCode") String sysCode){
        return sysLoginService.res(sysCode);
    }

}
